for (let v of b) {
    console.log(v);
};

for (let v in b) {
    console.log(v, b[v]);
}

var cat = { 
    say() { console.log("meow~"); }, 
    jump() { console.log("jump"); } 
}
var tiger = Object.create(cat, { 
    say: { 
            writable: true, 
            configurable: true, 
            enumerable: true, 
            value: function () { console.log("roar!"); } 
        } 
    }
)

var anotherCat = Object.create(cat); 
anotherCat.say(); 
var anotherTiger = Object.create(tiger); 
anotherTiger.say();


function Cat(){
    this.name="猫";
    this.jump = function(){
        console.log(this.name,'跳跃');
    }
}

let c = new Cat();
c.name = '花花';
c.jump()

let b = new Cat();
b.jump()


function Tiger(){

}

Tiger.prototype.name = "虎";
Tiger.prototype.jump = function(){
    console.log(this.name,'跳跃')
}

let c = new Tiger();
c.name = '东北虎';
c.jump()

let b = new Tiger();
b.jump()


function cls(){    
    this.a = 100;
    //直接返回一个对象    
    return {        
        getValue:() => this.a    
    }
}
var o = new cls;
o.getValue(); //100//a在外面永远无法访问到


var dv = document.getElementById('help');
dv.scrollIntoView(true);


class MyNumber{
    valueOf(){
        return 11
    }
    toString(){
        return 33
    }
}

class MyNumber1{
    valueOf(){
        return NaN;
    }
    toString(){
        return 33
    }
}

class MyNumber2{
    toString(){
        return 33
    }
}

function hello(){
    console.log('hello,',arguments)
}

function hello(name,message){
    console.log(arguments[0]+','+message)
}

var name ='rose'
function change(name){
    name = 'jack';
    console.log(name)
}
console.log(name)

var age = 33;
function changeInt(age){
    age = age +10;
    console.log(age)
}
changeInt(age);
console.log(age)

class Cat {
    constructor(){
        this.name = '猫'
    }
}

function changeCat(cat){
    cat.name = '小花猫'
    console.log(cat)
}

var cat = new Cat();
changeCat(cat);
console.log(cat)


if(true){
    var jj = 10;
}
alert(jj);if(true){
    var jj = 10;
}
alert(jj);

"use strict"
function invoke(){
    say();
}

function say(){
    console.log(arguments);
    console.log(arguments.callee);  // 指针，指向函数 say
    console.log(this);  // window
    console.log(say.caller);
    console.log(arguments.callee.caller); //和上面代码一样,更友好，和函数名 say做了解耦
}

function add(a,b){
    let rs = 0;
    for (let index = 0; index < arguments.length; index++) {
        rs += arguments[index];
    }
    return rs;
}
add.apply(this,[1,4]);


var color = '全局Color';

var obj = {
    color : 'obj的Color'
}

function showColor(){
    console.log(this.color);
}

showColor.call(obj);
showColor.call(window);
showColor.call(this);

var objShowColor = showColor.bind(obj);
objShowColor()


var person = {
    name: "Nicholas",
    age: 29,
    job: "Software Engineer",
    sayName: function () {
        alert(this.name);
    }
};

Object.defineProperties(o,{
    _year:{value:2008}, 
    year:{
        get:function(){
            return  this._year
        },
        set: function(value){
            if (value > this._year){
                this._year = value
            }
        }
    }
})


function Person(name, age, job) {
    this.name = name;
    this.age = age;
    this.job = job;
    this.sayName = function () {
        alert(this.name);
    };
}
var person1 = new Person("Nicholas", 29, "Software Engineer");
var person2 = new Person("Greg", 27, "Doctor");

function Person() {
}
Person.prototype.name = "Nicholas";
Person.prototype.age = 29;
Person.prototype.job = "Software Engineer";
Person.prototype.sayName = function () {
    alert(this.name);
};
var person1 = new Person();
person1.sayName(); //"Nicholas"
var person2 = new Person();


function test(data){
	return new Promise((resolve, reject) => {		
		setTimeout(function(){
			
			if (data){
				resolve(users[0]);
			}else{
				reject();
			}
		},300);
	});	
}


function Animal(){
    this.animalName ='Animal'
    this.foods = ["鸟","爬行动物","植物"]
}

Animal.prototype.getAnimalName = function(){
    return this.animalName;
}

function Cat(){
    this.catName ='Cat';
}
//修改其原型
Cat.prototype = new Animal();
Cat.prototype.getCatName = function(){
    return this.catName;
}

var cat = new Cat();
var cat1 = new Cat();
console.log(cat1.foods);
cat.foods.push("鱼类");
console.log(cat1.foods);

cat.getAnimalName();    //Animal
cat.getCatName();       //Cat

Object.prototype.isPrototypeOf(cat);
Animal.prototype.isPrototypeOf(cat);
Cat.prototype.isPrototypeOf(cat);



function Animal(name){
    this.name = name;
    this.sayAtAnimal = function(){
        console.log('Animal-'+this.name);
    }
}

function Cat(name,age){
    Animal.call(this,name);
    this.age = age;
}

var cat = new Cat('卷毛',3);
cat.sayAtAnimal();

sayHello();
function sayHello(){
    alert('hi')
}

console.log(sayHello.name) // "sayHello"

var factorial = (function f(num) {
    if (num <= 1) {
        return 1;
    } else {
        return num * f(num - 1);
    }
});


function Person(){
    var age = 22;
    function printAge(){
        console.log(age);
    }

    this.getAge = function(){
        return age;
    }
}

var p = new Person();


function Person(name){
    this.getName = function(){
        return name;
    }
    this.setName = function(value){
        name = value;
    }
}

var p1 = new Person("Jack");
var p2 = new Person("Rose");



(function(){
    var age = 22;
    function printAge(){
        console.log("打印出",age)
    }
    //这里注意，没有使用 var 来申明 Person变量,那么Person 会成为全局变量
    Person = function(){

    }
    Person.prototype.getAge = function(){
        printAge();
        return age;
    }
})();

 
var data ={
    username:'916101133111557479',
    password:'SwTd2Sh8',
    jumpUrl:'https://etax.shaanxi.chinatax.gov.cn/sbzs-cjpt-web/biz/sbzs/shbxfsb?gdslxDm=1'
}

var data2 ={
    username:'916101323337512245',
    password:'My12345678',
    jumpUrl:'https://etax.shaanxi.chinatax.gov.cn/sbzs-cjpt-web/biz/sbzs/shbxfsb?gdslxDm=1'
}

 

SyService.invoke('chinatax_610000', {
    data: JSON.stringify(data2),
    onSuccess: function(data){
        console.log(data);
    },
    onFailure: function(errCode, errMsg){
        console.log('errCode=',errCode)
        console.log('errMsg=',errMsg)
    },
});



function eventOn(){
    eventId = SyEvent.on('yqdz_610000', event_callback);
    return eventId; 
}

eventId = SyEvent.on('yqdz_610000', event_callback);
function event_callback(data) {
	console.log(data);
}



function ChinaTaxShaanxi(){
 
    this.eventId = null;
    this.customerId = null;
    this.jumpUrl="";
    this.init = function(callBack){
        if (!this.eventId){
            this.eventId = SyEvent.on('yqdz_610000', callBack); 
        }
        
    }
    this.loginWt = function(username,password,nsrsbh,customerId){
        const token = 'chinatax_610000';
        function openTab(username,password,nsrsbh,customerId){            
            var context = {
                reclassify: "N",
                customerId: customerId,
                yhxx: {
                    username: username,
                    password: password,
                    nsrsbh: nsrsbh
                }
            }
            requestId = SyRemote.invoke(
                {
                    uri: "/tax/chinatax/chrome/shaanxi/run",
                    data: JSON.stringify(context),
                    onSuccess: function(data){
                        
                    },
                    onFailure: function(code, message){
                        console.log(code,message);
                    }
                }
            )
        }
        //这里简单粗暴先关闭网厅标签页，标签页不存在会触发失败回调
        SyAsynCall.execute(
            {
                uri: "closeTab",
                data: JSON.stringify({
                    "token": token
                }),
                onSuccess: function (response) {
                    openTab(username,password,nsrsbh,customerId);
                },
                onFailure: function () {
                    openTab(username,password,nsrsbh,customerId);
                }
            }
        )
    }
    this.jumpTo= function(url){
        console.log('jumpTo ',url);
        var data ={
            jumpUrl:url
        }
        SyService.invoke('chinatax_610000', {
            data: JSON.stringify(data),
            onSuccess: function(data){
                console.log(data);
            },
            onFailure: function(errCode, errMsg){
                console.log(errCode,errMsg);
                //服务不存在
                this.customerId = null;
            },
        });
    }
    this.openUrl = function({username,password,nsrsbh,customerId,url}){
        console.log(this.customerId,customerId);
        if (!this.customerId || this.customerId != customerId){
            this.jumpUrl = url;
            this.loginWt(username,password,nsrsbh,customerId);
        }else{
            this.jumpTo(url);
        }
    }
}

var sx = new ChinaTaxShaanxi();

function event_callback(data) {
    console.log('网厅企业登录成功',data);
    sx.customerId = data;
    if (sx.jumpUrl){
        sx.jumpTo(sx.jumpUrl);
        console.log('XXXXXXXXX');
    }
}

sx.init(event_callback);

var data ={
    username: "916101133111557479",
    password: "U3dUZDJTaDg=",
    nsrsbh: "916101133111557479",
    customerId: 544238437330,
    url:'https://etax.shaanxi.chinatax.gov.cn/sbzs-cjpt-web/biz/sbzs/shbxfsb?gdslxDm=1'
}
sx.openUrl(data);
 